<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SSE Client</title>
</head>
<body>
<h1>SSE TEST</h1>
<div id="messages"></div>
<script>
  // 客户端连接时携带 ID
  const clientId = "client-123"; // 可替换为动态获取的 ID

  const eventSource = new EventSource(`https://sse.xinbanyue.com/events?id=${clientId}`);

  // 接收服务器发送的消息
  eventSource.onmessage = function(event) {
    console.log("Message received:", event.data);

    // 显示消息到页面ab -n 10000 -c 100 https://sse.xinbanyue.com/events?id=12345
    const messageDiv = document.getElementById("messages");
    const newMessage = document.createElement("p");
    newMessage.textContent = event.data;
    messageDiv.appendChild(newMessage);
  };

  // 处理 SSE 错误
  eventSource.onerror = function() {
    console.error("Error occurred while connecting to SSE server.");
  };
</script>
</body>
</html>
